package com.kaiwukj.android.ufamily;

import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.kaiwukj.android.mcas.di.component.AppComponent;
import com.kaiwukj.android.ufamily.app.MyApplication;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.DynamicListParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.DynamicPubParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommentResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.DynamicResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.TopicResult;
import com.kaiwukj.android.ufamily.mvp.model.DynamicModel;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class DynamicTest {

    DynamicModel mModel;

    @Before
    public void init() {
        AppComponent appComponent = MyApplication.getInstance().getAppComponent();
        mModel = new DynamicModel(appComponent.repositoryManager());
    }

    @Test
    public void testPublish() {
        DynamicPubParams params = new DynamicPubParams();
        params.setDynamicContent("我发布了一条动态");
        mModel.publishDynamic(params)
                .subscribe(new ApiCallBack<Integer>() {
                    @Override
                    public void onSuccess(@NonNull Integer result) {
                        LogUtils.d("result-------------------->" + GsonUtils.toJson(result));
                    }
                });
    }

    @Test
    public void testFetchDynamic() {
        DynamicListParams params = new DynamicListParams();
        mModel.fetchDynamic(params)
                // .compose(RxUtils.schedulerHelper())
                .subscribe(new ApiCallBack<ListResp<DynamicResult>>() {
                    @Override
                    public void onSuccess(@NonNull ListResp<DynamicResult> result) {
                        LogUtils.d("result-------------------->" + GsonUtils.toJson(result));
                    }
                });
    }

    @Test
    public void testFetchComment() {
        mModel.fetchComment(5, 1, 10)
                //  .compose(RxUtils.schedulerHelper())
                .subscribe(new ApiCallBack<ListResp<CommentResult>>() {
                    @Override
                    public void onSuccess(@NonNull ListResp<CommentResult> result) {
                        LogUtils.d("result---------------------->" + GsonUtils.toJson(result.getList()));
                    }
                });
    }

    @Test
    public void testFetchTopic() {
        mModel.fetchTopic("")
                .subscribe(new ApiCallBack<ListResp<TopicResult>>() {
                    @Override
                    public void onSuccess(@NonNull ListResp<TopicResult> result) {
                        LogUtils.d("result---------------------->" + GsonUtils.toJson(result.getList()));
                    }
                });
    }

    @Test
    public void testGetTopicById() {
        mModel.getTopicById(1)
                .subscribe(new ApiCallBack<TopicResult>() {
                    @Override
                    public void onSuccess(@NonNull TopicResult result) {
                        LogUtils.d("result---------------------->" + GsonUtils.toJson(result));
                    }
                });
    }


}
